<?php
declare (strict_types=1);

namespace app\course\service\exam\admin;

use app\common\service\BaseService;
use app\exam\logic\admin\PaperAnswerRecord;
use eduline\admin\libs\pagelist\ListItem;
use eduline\admin\page\PageList;
use think\annotation\Inject;

/**
 * Class Record
 *
 * @package app\course\service\exam\admin
 */
class Record extends BaseService
{
    /**
     * @Inject()
     *
     * @var PaperAnswerRecord
     */
    protected $paperAnswerRecord;

    /**
     * 课程考试记录
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/10/14
     *
     * @param int $courseId
     * @return \eduline\admin\page\interfaces\think\Response
     * @throws \think\db\exception\DbException
     */
    public function getCourseExamRecord(int $courseId, int $paperId)
    {
        $map  = [
            'paper_id'  => $paperId,
            'course_id' => $courseId
        ];
        $data = $this->paperAnswerRecord->getList($map, null, $courseId)->bindAttr('user', ['avatar_url', 'nick_name', 'phone'])->hidden(['user']);
        // 定义字段
        $keyList = [
            'user'        => ListItem::make('custom')->title('用户'),
            'paper_title' => ListItem::make()->title('试卷名称'),
            'paper_score' => ListItem::make()->title('总分数'),
            'user_score'  => ListItem::make()->title('得分'),
            'is_pass'     => ListItem::make('custom')->title('是否通过'),
            'time_takes'  => ListItem::make()->title('用时'),
            'topic_count' => ListItem::make()->title('题目总数'),
            'right_count' => ListItem::make()->title('正确数'),
            'commit_time' => ListItem::make()->title('交卷时间')
        ];

        // 设置表单
        $list = new PageList();
        // 表单字段
        $list->pageKey = $keyList;
        $list->datas   = $data;

        return $list->send();
    }
}